# import pandas
# import pymysql
# import sqlalchemy
# from sqlalchemy import create_engine
# import re
# import datetime

# #  中国科技大学：https://pypi.mirrors.ustc.edu.cn/simple/

# def sql_database(id):
#     to_day = datetime.date.today()
#     yesterday = to_day - datetime.timedelta(days=1)
#     # print(yesterday)
#     conn = pymysql.connect(host=r'sh-cdb-gv4u4x2m.sql.tencentcdb.com',user='jimclear',password='DvkcaJg2xpxU',database='rcmd_xiuzhou',port=59996)
#     sql_select = "select DISTINCT keywords from auto_download where store = 'swk赛维康旗舰店' and p_id != '下架' ;"
#     sql_select1 = "select count(convert(created,date)) as created_date from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' ;".format(str(to_day)[:7],id,yesterday)
#     sql_select2 = "select sum(market_order_cost) from zichun_t.`c_profit_suite_2024-03` where item_id = '648255354210'and created_date = '2024-03-25' and market_order_quantity = 1;"
#     sql_select3 = "select count(created) ,sum(asales)from zichun_t.`c_profit_suite_2024-03` where convert(created,date ) = '2024-03-25' and item_id = '648255354210';"
#     df = pandas.read_sql(sql=sql_select3,con=conn)
#     print(df["sum(asales)"]+1,type(df["sum(asales)"]))
#     conn.close()


# # sql_database(648255354210)
# print(datetime.timedelta(days=1))







# def sqllalchemy_sql():
#     connect_info = 'mysql+pymysql://jimclear:DvkcaJg2xpxU@sh-cdb-gv4u4x2m.sql.tencentcdb.com:59996/data_info'
#     engine = create_engine(connect_info)
#     # sql_cmd = """select DISTINCT keywords from auto_download"""#where store = 'swk赛维康旗舰店' and p_id != '下架' ;
#     # df = pandas.read_sql(sql=sql_cmd,con=engine)
#     # print(df)
#     # engine.close()
#     # conn = pymysql.connect(host=r'sh-cdb-gv4u4x2m.sql.tencentcdb.com',user='jimclear',password='DvkcaJg2xpxU',database='data_info',port=59996)
#     to_save = [['2024-03-27'+'696847743487','2024-03-27', '696847743487', '165', '8', 0.05, '3,235', '1069', '615', '62.39%', '20.58', 170, 0.16, 58, 112, 0.34, 0.66, 0.1, 20484.94, 14225.08, 6259.86, 120.5, 55.89, 19.51, '10', '6', 1.67, '15.29%同类商品平均15.32%', '0.53%同类商品平均0.46%', '36', '190', 'https://img.alicdn.com/tfs/TB1MANcRVXXXXcKaXXXXXXXXXXX-22-26.png', 0.02, 0.08, 0.09, '4.30%', '335.39', '20', '2691.72', '8.03', 0.42, 5993.71],
#     ['2024-03-27'+'696847743488','2024-03-27', '696847743488', '165', '8', 0.05, '3,235', '1069', '615', '62.39%', '20.58', 170, 0.16, 58, 112, 0.34, 0.66, 0.1, 20484.94, 14225.08, 6259.86, 120.5, 55.89, 19.51, '10', '6', 1.67, '15.29%同类商品平均15.32%', '0.53%同类商品平均0.46%', '36', '190', 'https://img.alicdn.com/tfs/TB1MANcRVXXXXcKaXXXXXXXXXXX-22-26.png', 0.02, 0.08, 0.09, '4.30%', '335.39', '20', '2691.72', '8.03', 0.42, 5993.71]]
#     to_2 = pandas.DataFrame(to_save,columns=['update_time_item_id', 'update_time', 'item_id', 'PC_exposure', 'PC_click_through_rate', 'Click_through_rate', 'View_volume', 'Visitor_count', 'Search_for_visitors', 'Bounce_rate', 'Duration_of_stay', 'Total_number_of_orders', 'Conversion_rate', 'Marketing_quantity', 'Number_of_orders_issued', 'Proportion_of_supplementary_orders', 'Brushing_proportion', 'Order_conversion_rate', 'Total_payment_amount', 'Payment_amount_for_issuing_documents', 'Marketing_amount', 'Customer_unit_price', 'Order_per_customer_price', 'UV_value', 'Number_of_consultations', 'Transaction_quantity', 'Inquiry_conversion_rate', 'Refund_rate', 'Quality_refund_rate', 'Number_of_Collections', 'Additional_purchases', 'Industry_ranking', 'Order_growth_rate', 'out_Order_growth_rate', 'Visitor_growth_rate', 'Main_image_click_through_rate', 'Direct_train_expenses', 'Number_of_direct_transactions', 'Direct_transaction_amount', 'Direct_output_ratio', 'profit_rate', 'Net_profit'])
#     print(to_2)
#     to_2.to_sql("core_data",con=engine,if_exists="append",index=False)
#     # engine.close()

# # sqllalchemy_sql()
# # sql_database()

# print("{}".format(1))


# def j():
#     print(3)
    

# def i(o):
#     print(2)
#     e = o
#     print(5)
#     return e


# # y = i(j)

# # y()

# def func1():
#     list1 = ['共35条记录', '共7条记录', 'swk赛维康电动洗鼻器儿童家用鼻腔冲洗冲鼻器成人鼻炎洗鼻子神器\nID: 648255354210上架1012天', '爆品期', '当前GMV排名较高，继续保持\n成交排名: 1', '\ue6cb', '1,644,629.99环比\n+26.9%\n同行同层\n120,047.08', '160,889环比\n+29.9%\n同行同层\n35,680', '9,978环比\n+52.4%\n同行同层\n11,290', '13,443.76环比\n+56.6%', '13.04环比\n-20.2%', '7.12%环比\n-1.9%\n同行同层\n7.31%', '4.41%环比\n-4.7%\n同行同层\n5.78%', '6.70%环比\n-2.5%', '82,941环比\n+28.5%\n同行同层\n3,671,358', '6.43%环比\n+3.0%\n同行同层\n4.12%', '2024-03-24', '648255354210', 'swk赛维康电动洗鼻器儿童家用鼻腔冲洗冲鼻器成人鼻炎洗鼻子神器', '_', '2,332', '2,331', '_', '66.42%', '50%', '66.45%', '27.19', '27.15', '80.20', '70,632.56', '2', '483', '1', '482', '71', '13', '58', '_', '70,632.56', '323', '_', '323', '321', '0', '321', '220.04', '_', '220.04', '13.77%', '0%', '13.77%', '6,817', '6,812', '5', '17,798.59', '337', '352', '76,660.04', 'swk赛维康旗舰店', '2024-03-24', '70,633', '2,332', '1,470', '71', '441', '13.76%', '321', '323', '220.12', '30.29', '63.04%', '3.04%', '18.91%', 'https://img.alicdn.com/tfs/TB16l8lRVXXXXXvaXXXXXXXXXXX-22-26.png', '18.87%', '0.37%', '5,551', '240', '600.00', '4.32%', '2.50', '6,455.76', '31', '12.92%', '31', '3', '0', '3', '200.00', '5,491.85', '24', '963.91', '7', '10.76']
#     # for i in list1:
#     to_all = [i.split("环比")[0] if "环比" in i else i for i in list1]
#     # print(float(to_all[6].replace(",","")))
#     print(to_all[19])
#     print(to_all[22])
#     all = "_" if to_all[19] == "_" or to_all[22] == "_" else int(to_all[22])/int(to_all[19])
#     print(all)
#     print("--------")
#     print(to_all[20].replace(",",""))
#     print(float(to_all[69]))
#     to_all[0] = re.findall("\d+",to_all[0])[0]
#     to_all[1] = re.findall("\d+",to_all[1])[0]
#     print()
#     print(re.findall("\d+",to_all[1])[0])
#     print("-------------------")
   
#     print(int(to_all[0])/int(to_all[1]))
#     print("---------------")
# # to_all[36],to_all[33],to_all[73],to_all[15],to_all[78],to_all[82],to_all[81],to_all[93]
#     print(to_all[36])
#     print(to_all[33])
#     print(to_all[73])
#     print(to_all[15])
#     print(to_all[78])
#     print(to_all[82])
#     print(to_all[81])

#     print(to_all[93])
#     # print(to_all[19])
#     # print(to_all[19])
#     # print(to_all[19])
#     #     to_all = [to_all[19],to_all[22],int(to_all[22])/int(to_all[19]),to_all[20],to_all[69],to_all[0],to_all[1],int(to_all[0])/int(to_all[1]),to_all[36],to_all[33],to_all[73],to_all[15],to_all[78],to_all[82],to_all[81],to_all[93]]#待编译

# # func1()
    
# # to_all = ['10', '7', 'swk赛维康婴儿款电子体温枪额耳温枪温度计医专用精准高精度家用\nID: 696847743487上架445天', '爆品期', '当前GMV排名较高，继续保持\n成交排名: 9', '\ue6cb', '1,029,808.77', '154,619', '13,893', '13,481.82', '9.60', '6.82%', '5.27%', '5.24%', '88,502', '4.26%', '2024-03-25', '696847743487', 'swk赛维康婴儿款电子体温枪额耳温枪温度计医专用精准高精度家用', '135', '1187', '1,176', '6', '63.77%', '_', '63.44%', '21.53', '20.70', '268.09', '20,217.35', '11', '190', '_', '190', '41', '5', '36', '_', '20,217.35', '155', '_', '155', '152', '0', '152', '133.01', '_', '133.01', '12.81%', '0%', '12.93%', '3,300', '3,289', '11', '2,338.65', '153', '159', '20,709.35', 'swk赛维康旗舰店', '2024-03-25', '20,217', '1,187', '739', '41', '180', '12.81%', '152', '155', '132.96', 17.03, '62.26%', '3.45%', '15.16%', '5', '18.66%同类商品平均15.80%', '0.36%同类商品平均0.25%', '5,414', '229', '430.35', '4.23%', '1.88', '2151.70', '17', '7.42%', '23', '1', '1', '2', '430.35', '2,151.70', '17', '0.00', '0', '5.00']
# # to_1 = "_" if to_all[19] == "_" or to_all[22] == "_" else int(to_all[22])/int(to_all[19])
# # print(to_all[19],to_all[22],to_1,to_all[20],to_all[69],to_all[0],to_all[1],int(to_all[0])/int(to_all[1]),to_all[36],to_all[33],to_all[73],to_all[15],to_all[78],to_all[82],to_all[81],to_all[93])
# # to_1.columns = ["PC端曝光量",	"PC端点击量",	"点击率",	"浏览量","uv价值",	"咨询数量",	"成交数量",	"询单转化率",	"退款率",	"品质退款率",	"收藏数",	"加购数",	"行业排名","主图点击率（达摩盘）",	"直通车花费",	"直接成交笔数",	"直接成交金额",	"直接产出比"]


# # print(len(to_all))
# #,to_all[94],to_all[95]

# # to_day = datetime.date.today()
# # print(to_day,type(to_day))
# # print(str(to_day)[:7])





# def sql_database(id):
#     to_day = datetime.date.today()
#     yesterday = to_day - datetime.timedelta(days=1)
#     qian_today = to_day - datetime.timedelta(days=2)

#     conn = pymysql.connect(host=r'sh-cdb-gv4u4x2m.sql.tencentcdb.com',user='jimclear',password='DvkcaJg2xpxU',database='rcmd_xiuzhou',port=59996)
#     # # sql_select = "select DISTINCT keywords from auto_download where store = 'swk赛维康旗舰店' and p_id != '下架' ;"
#     # sql_select1 = "select count(convert(created,date)) as created_date from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' ;".format(str(to_day)[:7],id,yesterday)
#     # df1 = pandas.read_sql(sql=sql_select1,con=conn)["created_date"][0]#总订单数
#     # print("总订单数:",df1)
#     # sql_select2 = "select count(convert(created,date)) as created_date from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}'and market_order_quantity = 1 ;".format(str(to_day)[:7],id,yesterday)
#     # df2 = pandas.read_sql(sql=sql_select2,con=conn)["created_date"][0]#营销数
#     # print("营销数:",df2)
#     # df3 = df1 - df2 #出单订单数
#     # print("出单订单数:",df3)
#     # sql_select3 ="select sum(sales_volume) from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}'".format(str(to_day)[:7],id,yesterday)
#     # df4 = pandas.read_sql(sql=sql_select3,con=conn)["sum(sales_volume)"][0]#总支付金额
#     # print("总支付金额",df4)
#     # sql_select4 = "select sum(market_order_cost),sum(asales) from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' and market_order_quantity = 1;".format(str(to_day)[:7],id,yesterday)
#     # df5 = pandas.read_sql(sql=sql_select4,con=conn)["sum(market_order_cost)"][0]##营销金额，
#     # sql_select9 = "select sum(asales) from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' ;".format(str(to_day)[:7],id,yesterday)
#     # df6 = pandas.read_sql(sql=sql_select9,con=conn)["sum(asales)"][0]#出单支付金额
#     # # print("---",sql_select9)
#     # print("营销金额:",df5)
#     # # print("===",df5["sum(asales)"])
#     # print("出单支付金额:",df6)
#     # df6 = df3/df1     #刷占比
#     # print("刷占比:",df6)
#     # df7 = df2/df1#补单占比
#     # print("补单占比:",df7)
#     # # df8 = #出单转化率
#     # df9 = df4/df1#客单价
#     # print("客单价:",df9)
#     # df10 = df5/df3#出单客单价
#     # print("出单客单价:",df10)
#     # # sql_select5 = "select count(market_order_cost),sum(asales) from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' and market_order_quantity = 1;".format(str(to_day)[:7],id,yesterday)#前天数据
#     # sql_select6 = "select count(convert(created,date)) as created_date from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}' ;".format(str(to_day)[:7],id,qian_today)
#     # df11 = pandas.read_sql(sql=sql_select6,con=conn)["created_date"][0]#昨日总订单数
#     # df12 = (df1-df11)/df1#订单增长率
#     # print("订单增长率:",df12)
#     # sql_select7 = "select count(convert(created,date)) as created_date from zichun_t.`c_profit_suite_{}` where item_id = '{}'and created_date = '{}'and market_order_quantity = 1 ;".format(str(to_day)[:7],id,qian_today)
#     # df13 = pandas.read_sql(sql=sql_select7,con=conn)["created_date"][0]#前日营销数
#     # df17 = (df3-(df11-df13))/df3#出单订单增长率
#     # print("出单订单增长率:",df17)
#     sql_select8 = "select sum(gross_profit),sum(market_order_comm),sum(market_order_points),sum(market_order_freight),sum(eval_other),sum(exchange_refund),sum(cus_ser_discount) from zichun_t.`c_profit_suite_{}` where item_id = '{}' and convert(created,date) = '{}';".format(str(to_day)[:7],id,yesterday)
#     df14 = pandas.read_sql(sql=sql_select8,con=conn)#毛利，营销扣点，营销运费，营销佣金，评价，客服折扣，退差
#     df15 = df14["sum(gross_profit)"][0]#毛利
#     print("毛利:",df15)
#     print("333333333333333",df14["sum(market_order_comm)"])
#     print(0 if str(type(df14["sum(market_order_points)"][0])) == "<class 'NoneType'>" else 9999999,type(df14["sum(market_order_points)"][0]))
#     print(df14["sum(market_order_freight)"])
#     print(df14["sum(eval_other)"])#sum(eval_other),sum(exchange_refund),sum(cus_ser_discount)
#     print(df14["sum(exchange_refund)"])
#     print(df14["sum(cus_ser_discount)"])
#     # print("000000000",(df14["sum(market_order_comm)"][0]+df14["sum(market_order_points)"][0]+df14["sum(market_order_freight)"][0]+df14["sum(eval_other)"][0]+df14["sum(exchange_refund)"][0]+df14["sum(cus_ser_discount)"][0]))
#     # sql_select10 = "select total from zichun_t.c_software_fee_day where item_id = '{}' and date = '{}';".format(id,yesterday)
#     # df18 = pandas.read_sql(sql=sql_select10,con=conn)["total"][0]#软件费用

#     # df16 = (df15 - (df14["sum(market_order_comm)"][0]+df14["sum(market_order_points)"][0]+df14["sum(market_order_freight)"][0]+df14["sum(eval_other)"][0]+df14["sum(exchange_refund)"][0]+df14["sum(cus_ser_discount)"][0]+df18))#/(df4-df5)
#     # print("利润率:",df16)
#     conn.close()



# # sql_database(6482553542103)

# def data_():
#     conn = pymysql.connect(host=r'sh-cdb-gv4u4x2m.sql.tencentcdb.com',user='jimclear',password='DvkcaJg2xpxU',database='data_info',port=59996)
#     select_sql = "select item_id,Competitors_item_id from data_info.Operations_fill_real_time_core_data WHERE state = TRUE;"
#     select_pandas = pandas.read_sql(sql=select_sql,con=conn)
#     # print(select_pandas)
#     data_id_all = [i for i in select_pandas["item_id"]]
#     data_Competitors_item_id = [list(zip(i.split("、")[::2], i.split("、")[1::2])) for i in select_pandas["Competitors_item_id"]]
#     # print(data_Competitors_item_id)
#     # list_data_Competitors_item_id = list(zip(i.split("、")[::2], i.split("、")[1::2]))
#     print([data_id_all,data_Competitors_item_id])

# # data_()
    
from dingtalkchatbot.chatbot import DingtalkChatbot
def send_text():
    # 创建一个机器人
    webhook = 'https://oapi.dingtalk.com/robot/send?access_token=353790a35216b1096abea413d24cdf3b26475303b93574359c5f4f98575670cc'
    secret = 'SECd3a56ed275da8f652eb45a8cb3fb7ae1c9f0986b1a3371266aeaf09030261ec4'
    bot = DingtalkChatbot(webhook,secret,fail_notice=True)
    # 发送消息
    bot.send_text(msg="测试数据。",at_mobiles=["17513168339","17317512397"])

send_text()

# import json
# import time
# import requests

# def send_ding_message(message):
#     url = f'https://oapi.dingtalk.com/robot/send?access_token=353790a35216b1096abea413d24cdf3b26475303b93574359c5f4f98575670cc'

#     HEADERS = {
#         "Content-Type": "application/json ;charset=utf-8 "
#     }
#     String_textMsg = {
#         "msgtype": "markdown",
#         "markdown":
#             {
#                 'title':'测试测试',
#                 "text": message
#                 },
#         "at": {
#             "atMobiles": [
#                 "13200000000"
#             ],
#             "isAtAll": 0
#         }
#     }
#     String_textMsg = json.dumps(String_textMsg)
#     res = requests.post(url, data=String_textMsg, headers=HEADERS)
#     print(res.text)
#     return res.text

# if __name__ == '__main__':

#     # 钉钉部分
#     ding_msg = [
#         f'「****************{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())))}***************」']
#     ding_msg.append(f'<font color=#0000FF>蓝色试下</font>\n\n')
#     ding = "\n".join(ding_msg)
#     res = send_ding_message(f'{ding}\n- 本次运行结束')

